Skip to content

Fix GH-16186: Ignore scope when compiling closure in non-tracing jit #16200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Oct 3, 2024

Fixes GH-16186.

zend_jit() assumes that Closure op_arrays have no scope, but this is not true for all triggers. E.g. with the hot counter trigger, the op_array is a copy with a scope.

As a result, we assume the class of $this here, but it is later changed in ::bind(), which causes the issue.

Here I copy what is done for the tracing JIT: Use the original op_array, which has no scope.

@arnaud-lb arnaud-lb force-pushed the gh16186 branch 2 times, most recently from 56e1803 to edc010b Compare October 3, 2024 16:05
@arnaud-lb arnaud-lb changed the base branch from master to PHP-8.4 October 3, 2024 16:06
@arnaud-lb arnaud-lb changed the title Ignore scope when compiling closure in non-tracing jit Fix GH-16186: Ignore scope when compiling closure in non-tracing jit Oct 3, 2024
@arnaud-lb arnaud-lb marked this pull request as ready for review October 4, 2024 12:22
@arnaud-lb arnaud-lb requested a review from dstogov as a code owner October 4, 2024 12:22
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you approach is right.

Personally, I would try to fix all the places where ``op_array->scope" is used, but this would going to be more complex and error prone...

Comment on lines +2824 to +2831
if (JIT_G(trigger) == ZEND_JIT_ON_FIRST_EXEC) {
zend_jit_op_array_extension *jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
op_array = (zend_op_array*) jit_extension->op_array;
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_COUNTERS) {
zend_jit_op_array_hot_extension *jit_extension = (zend_jit_op_array_hot_extension*)ZEND_FUNC_INFO(op_array);
op_array = (zend_op_array*) jit_extension->op_array;
} else {
ZEND_ASSERT(!op_array->scope);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about ZEND_FUNC_JIT_ON_PROF_REQUEST?

Copy link
Member Author

@arnaud-lb arnaud-lb Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it here initially, but I then I figured that it was not necessary because we never compile closures in ZEND_FUNC_JIT_ON_PROF_REQUEST mode (according to my understanding of zend_jit_check_funcs()). In theory we could compile closures in zend_jit_check_funcs() by also iterating over op_array->dynamic_func_defs, but in this case we would get the right op_array, so fetching it from jit_extension would not be necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@arnaud-lb
Copy link
Member Author

Personally, I would try to fix all the places where ``op_array->scope" is used, but this would going to be more complex and error prone...

I considered this, but I agree it would be more error prone. I didn't see possible drawbacks of the current approach, especially since the tracing JIT does this too (although it's possibly for a different reason).

@arnaud-lb arnaud-lb closed this in 82f70db Oct 7, 2024
arnaud-lb added a commit that referenced this pull request Oct 7, 2024
arnaud-lb added a commit that referenced this pull request Oct 7, 2024
* PHP-8.4:
  NEWS for GH-16200
  Use original op_array when JIT compiling a Closure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion failure in Zend/zend_operators.c:2708
2 participants